package com.glory.good_dark.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;

import com.glory.good_dark.application.App;
import com.glory.good_dark.utils.JurisdictionUtils;
import com.pda.platform.ui.ui_pdaplatform.base.FreeUI_BaseActivity;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_CommonCallback;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_TextCallback;
import com.pda.platform.ui.ui_pdaplatform.dialog.FreeUI_GeneralFragmentDialog;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_AddViewEntity;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_ActivityManager;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_DialogUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_SharePreferencesUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_StaticMembers;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_Utils;

/**
 * @author yi.zhang
 * @date 2019/6/11
 * @desc 跳转处理类
 */
public class DialogActivity extends FreeUI_BaseActivity {


    private FreeUI_GeneralFragmentDialog inputFragmentDialog;

    private String extra;

    @Override
    protected int getLayoutResId() {
        return 0;
    }

    @SuppressLint("ApplySharedPref")
    @Override
    protected void initView() {

        extra = getIntent().getStringExtra(FreeApi_StaticMembers.SHOW_PLUGIN_KEY);
        //切换用户
        if(extra.equals("SwitchingUsers"))
        {
            SharedPreferences userSettings = getSharedPreferences("GOODARK_FILE",Activity.MODE_PRIVATE);
            SharedPreferences.Editor editor = userSettings.edit();
            editor.clear();
            editor.commit();
            FreeApi_ActivityManager.getActivityManager().finishAllActivity();
            startActivity(new Intent(DialogActivity.this, LoginActivity.class));
            return;
        }
        //退出
        if(extra.equals("Exit"))
        {
            FreeApi_DialogUtils.getConfirmAndCancelDialog(App.app, "您确定要退出吗？", new FreeUI_CommonCallback() {
                @Override
                public void onSuccess() {
                    FreeApi_ActivityManager.getActivityManager().AppExit(DialogActivity.this);
                }
            }, new FreeUI_CommonCallback() {
                @Override
                public void onSuccess() {
                    DialogActivity.this.finish();
                    FreeApi_ActivityManager.getActivityManager().finishActivity();
                }
            }).show(getSupportFragmentManager(),"Exit_DIALOG");
            return;
        }

        if(JurisdictionUtils.checkActivity(extra)) {

        }else{
            inputFragmentDialog = FreeApi_DialogUtils.getConfirmDialog(this, "确定","无权限", new FreeUI_CommonCallback() {
                @Override
                public void onSuccess() {
                    inputFragmentDialog.dismiss();
                }
            });

            inputFragmentDialog.setCallBack(new FreeUI_CommonCallback() {
                @Override
                public void onSuccess() {
                    DialogActivity.this.finish();
                    FreeApi_ActivityManager.getActivityManager().finishActivity();
                }
            });
            inputFragmentDialog.show(getSupportFragmentManager(), "AUTH_DIALOG");
            return;
        }

        if (extra.equals("PMQueryActivity")){
            inputFragmentDialog = FreeApi_DialogUtils.getScanDialog(this, "请扫描工序", new FreeUI_TextCallback() {
                @Override
                public void onSuccess(String str) {
                    Jump(str);
                    inputFragmentDialog.dismiss();
                }
            });

            inputFragmentDialog.setCallBack(new FreeUI_CommonCallback() {
                @Override
                public void onSuccess() {
                    DialogActivity.this.finish();
                    FreeApi_ActivityManager.getActivityManager().finishActivity();
                }
            });
            inputFragmentDialog.show(getSupportFragmentManager(), "URL_IP_DIALOG");
            return;
        }

        if(!extra.equals("BoxWarehousingActivity")&&!extra.equals("BatchCurrentInfoActivity")&&!extra.equals("CurrentDeviceWorkInfoActivity")&&!extra.equals("OneselfDeviceWorkInfoActivity")&&!extra.equals("MaterielSearchActivity")) {

            inputFragmentDialog = FreeApi_DialogUtils.getScanDialog(this, "请扫描设备", new FreeUI_TextCallback() {
                @Override
                public void onSuccess(String str) {
                    if (str.contains("(R)")){
                        str = str.replace("(R)", "");
                    }

                    Log.e("replace", "print=" + str);
                    App.EQPID = str;
                    FreeApi_SharePreferencesUtils.setSharePre("GOODARK_FILE", "EQP_ID", str, App.app);
                    Jump(str);
                    inputFragmentDialog.dismiss();
                }
            });

            inputFragmentDialog.setCallBack(new FreeUI_CommonCallback() {
                @Override
                public void onSuccess() {
                    DialogActivity.this.finish();
                    FreeApi_ActivityManager.getActivityManager().finishActivity();
                }
            });
            inputFragmentDialog.show(getSupportFragmentManager(), "URL_IP_DIALOG");

        }else{
            Jump(App.EQPID);
            DialogActivity.this.finish();
            FreeApi_ActivityManager.getActivityManager().finishActivity();
        }
    }

    private void Jump(String str)
    {
        Bundle bundle = new Bundle();
        bundle.putString("EQPID",str);
        switch (extra){
            //多批次进站
            case "MultiBatchStartActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, MultiBatchStartActivity.class);
                break;
             //多批次逐批出站
            case "MultiBatchEndActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, MultiBatchEndActivity.class);
                break;
            //批次开始操作
            case "SingleBatchStartActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, SingleBatchStartActivity.class);
                break;
            //批次结束操作
            case "BatchWorkEndActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, BatchWorkEndActivity.class);
                break;
            //材料更换
            case "MaterielFoolProofingActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, MaterielFoolProofingActivity.class);
                break;
            //更改设备状态
            case "RecipeInfoActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, RecipeInfoActivity.class);
                break;
            //日检
            case "DailyInspectionActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, LoginActivity.class);
                break;
            //点检确认
            case "DailyInspectionConfirmActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, LoginActivity.class);
                break;
            //维修
            case "MaintainManageActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, LoginActivity.class);
                break;
            //解锁
            case "UnlockActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, UnlockActivity.class);
                break;
            //锁机
            case "LockmachineActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this,LockmachineActivity.class);
                break;
            //清除批次
            case "BatchClearActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, LoginActivity.class);
                break;
            //拆卡退回
            case "DiscardsBackActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, LoginActivity.class);
                break;
            //箱号入库
            case "BoxWarehousingActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, LoginActivity.class);
                break;
            //保养管理
            case "MaintenanceActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, LoginActivity.class);
                break;
            //打印作业
            case "PrintJobActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, LoginActivity.class);
                break;
            //批次当前信息查询
            case "BatchCurrentInfoActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, LoginActivity.class);
                break;
            //当前设备作业量
            case "CurrentDeviceWorkInfoActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, LoginActivity.class);
                break;
            //本人设备作业信息
            case "OneselfDeviceWorkInfoActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, LoginActivity.class);
                break;
            //设备当前物料查询
            case "MaterielSearchActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, LoginActivity.class);
                break;
            //更换设备
            case "RreplaceDeviceActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, LoginActivity.class);
                break;
                //工程模式
            case "ProjectModelActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, ProjectModelActivity.class);
                break;
                //PM管理
            case "PMMangerActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, PMMangerActivity.class);
                break;
            case "PPAKWorkEndActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, PPAKWorkEndActivity.class);
                break;
                //系统配置
            case "SystemConfigActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, SystemConfigActivity.class);
                break;
                //Stripid管理
            case "StripIDMangerActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, StripIDMangerActivity.class);
                break;
                //PM查询
            case "PMQueryActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, PMQueryActivity.class);
                break;
            //合批
            case "MergeLotActivity":
                FreeApi_Utils.skipWithExtraIntent("header",bundle, DialogActivity.this, MergeLotActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    protected FreeUI_AddViewEntity getBaseEntity() {
        return null;
    }
}
